var config = require('../config/settings');
var qiniu = require("qiniu");

//需要填写你的 Access Key 和 Secret Key
qiniu.conf.ACCESS_KEY = config.ACCESS_KEY;
qiniu.conf.SECRET_KEY = config.SECRET_KEY;

//要上传的空间
var bucket = config.Bucket_Name;

//上传函数
function uploadFile(name, localFile, callback) {

    //生成上传 Token
    var token = new qiniu.rs.PutPolicy(bucket + ":" + name).token();

    //上传
    qiniu.io.putFile(token, name, localFile, new qiniu.io.PutExtra(), function (err, ret) {
        callback(err, ret);
    });
}

module.exports = {
    upload: uploadFile
};